{block name="circle_layout"}
	{include file="common:common_layout"}
{/block}
{extend name="common/layout" /}
{block name="style"}{/block}
{block name="content"}
<div class="base-layout">
    <div class="mainbox">
        {include file="circle:manage:top" /}
        
        <form id="circle_level" name="circle_level" method="post" action="{:url('circle/managelevel/level')}?c_id=<?php echo $c_id; ?>">
            <table class="base-table-style">
                <thead>
                <tr>
                    <th colspan="15" class="tl"> <ul class="level-set">
                        <li>
                            <input type="radio" name="levelset" nctype="levelset" <?php if($ml_info['mlref_id'] === '0'){?>checked="checked"<?php }?> id="levelset0" checked="checked" value="0" data-param="<?php echo str_replace('"',"'",json_encode($mld_array));?>" />
                            <label for="levelset0">默认系列</label>
                        </li>
                        <?php if(!empty($mlr_array)){?>
                        <?php foreach (($mlr_array) as $key=>$val){?>
                        <li>
                            <input type="radio" name="levelset" nctype="levelset" <?php if($ml_info['mlref_id'] == $key){?>checked="checked"<?php }?> id="levelset<?php echo $key;?>" value="<?php echo $key;?>" data-param="<?php echo str_replace('"',"'",json_encode($val['info']));?>" />
                            <label for="levelset<?php echo $key;?>"><?php echo $val['name'];?></label>
                        </li>
                        <?php }?>
                        <?php }?>
                        <li>
                            <input type="radio" name="levelset" id="user-defined" <?php if(!empty($ml_info) && $ml_info['mlref_id'] == null){?>checked="checked" data-param="<?php echo str_replace('"',"'",json_encode($ml_info['info']));?>"<?php }?> value="custom" />
                            <label for="user-defined">自定义</label>
                        </li>
                    </ul>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td class="w100">级别</td>
                    <td class="w100">经验</td>
                    <td>头衔</td>
                    <td class="w100">级别</td>
                    <td class="w100">经验</td>
                    <td>头衔</td>
                </tr>
                <?php if(!empty($mld_array)){?>
                <?php for($i=1;$i<=8;$i++){?>
                <tr>
                    <td><span class="member-level member-level-<?php echo $i;?>"><strong><?php echo $i;?></strong></span></td>
                    <td><?php echo $mld_array[$i]['exp'];?></td>
                    <td nctype="mlname<?php echo $i;?>"><span class="member-level-name"><?php echo $mld_array[$i]['name'];?></span></td>
                    <td><span class="member-level member-level-<?php echo $i+8;?>"><strong><?php echo $i+8;?></strong></span></td>
                    <td><?php echo $mld_array[$i+8]['exp'];?></td>
                    <td nctype="mlname<?php echo $i+8;?>"><span class="member-level-name"><?php echo $mld_array[$i+8]['name'];?></span></td>
                </tr>
                <?php }?>
                <?php }?>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="10" class="bottom tc"><a href="JavaScript:void(0);" class="submit-btn" nctype="submitBtn" style="display: inline-block; float: none; margin: 10px auto 20px auto;">提交设置</a></td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
    <div class="sidebar">
        {include file="circle:manage:sidebar" /}

    </div>
</div>
<script type="text/javascript" src="__SITE_RESOURCE__/js/jquery.validation.min.js"></script>
<script>
    $(function(){
        // init
        var _this = $('.level-set').find('input:checked')
        $val = _this.val();
        if($val != 0 && $val != 'custom'){
            checkedLevel(_this);
        }else if($val == 'custom'){
            customLevel(_this);
        }

        // submit
        $('a[nctype="submitBtn"]').click(function(){
            ajaxpost('circle_level', '', '', 'onerror');
        });

        $('input[nctype="levelset"]').click(function(){
            checkedLevel($(this));
        });

        $('#user-defined').click(function(){
            customLevel($(this));
        });
    });
    function checkedLevel($this){
        var data_str = $this.attr('data-param'); eval(' data_str = '+data_str);
        for($i=1;$i<=16;$i++){
            $('td[nctype="mlname'+$i+'"]').html('<span class="member-level-name">'+data_str[$i].name+'</span>');
        }
    }
    function customLevel($this){
        var _sign = typeof($this.attr('data-param')) == 'undefined' ?　false : true ;
        if(_sign){
            var data_str = $this.attr('data-param'); eval(' data_str = '+data_str);
        }
        for($i=1;$i<=16;$i++){
            if(_sign){
                $('td[nctype="mlname'+$i+'"]').html('<input type="text" class="text w100" name="levelname['+$i+']" value="'+data_str[$i].name+'" maxlength="4" />');
            }else{
                $('td[nctype="mlname'+$i+'"]').html('<input type="text" class="text w100" name="levelname['+$i+']" maxlength="4" />');
            }
        }
    }
</script>
{/block}